package cn.xzz.pethome.share.utils;

import lombok.Getter;
import lombok.ToString;

@ToString
@Getter
public class AjaxResult {
    //私有构造方法
    private AjaxResult(){}

    //定义状态提示
    private Boolean state = true;
    //定义信息提示
    private String masg = "操作成功";

    //成功后返回一个默认值的ajaxResult对象
    public static AjaxResult win(){
        return my();
    }

    //失败后返回一个自定义的ajaxResult对象
    public static AjaxResult lose(){
        return my().setState(false).setMasg("操作失败,请稍后再试!");
    }

    //创建唯一对象
    public static AjaxResult my(){
        return new AjaxResult();
    }

    //链式编程
    //返回一个状态state
    public AjaxResult setState(Boolean state){
        this.state = state;
        return this;
    }

    //返回一个masg信息提示
    public AjaxResult setMasg(String masg){
        this.masg = masg;
        return this;
    }

}
